package JSE_02.Collections.Demo02;

import java.util.ArrayList;
import java.util.Collections;

public class Demo02Sort {
    public static void main(String[] args) {
        ArrayList<Integer> arr00=new ArrayList<>();
        arr00.add(2);
        arr00.add(3);
        arr00.add(4);
        arr00.add(1);
        System.out.println(arr00);
        System.out.println("==============");
        Collections.sort(arr00); // 升序
        System.out.println(arr00);

        System.out.println("==============");
        ArrayList<Character> arr01=new ArrayList<>();
        arr01.add('B');
        arr01.add('C');
        arr01.add('D');
        arr01.add('A');
        System.out.println(arr01);
        System.out.println("==============");
        Collections.sort(arr01);
        System.out.println(arr01);

        System.out.println("==============");

        ArrayList<Person> p00=new ArrayList<>();
        // Integer、String、Character...都实现了Comparable接口
        // 要实现自定义排序 只要重写它的compareTo方法就行
        p00.add(new Person("小美",28));
        p00.add(new Person("小红",11));
        p00.add(new Person("小婷",13));
        Collections.sort(p00);
        System.out.println(p00);

    }
}
